package com.bdult.vh.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.bdult.vh.common.CommonUtil;
import com.bdult.vh.service.EventService;
import com.bdult.vh.service.ItemService;

/**
 * Handles requests for the application home page.
 */
@Controller
public class EventController {
	
	private static final Logger logger = LoggerFactory.getLogger(EventController.class);
	
	@Autowired
	private ItemService itemService;
	
	@Autowired
	private EventService eventService;
	
	@RequestMapping(value="showtime")
	public ModelAndView showtime(Model model) {
		ModelAndView mv = new ModelAndView();
		
		ArrayList<HashMap<String,String>> showtimeList = new ArrayList<HashMap<String,String>>();		
		showtimeList = eventService.getShowTimeList();
		System.out.println("showtimeList = " + showtimeList);
		mv.addObject("showtimeList", showtimeList);
		mv.setViewName("showtime");
		mv.addObject("LOC", "SHOWTIME");
		return mv;
	}
	
	@RequestMapping(value="promotion")
	public ModelAndView promotion(Model model) {
		ModelAndView mv = new ModelAndView();
		
		mv.setViewName("promotion");
		mv.addObject("LOC", "PROMOTION");
		return mv;
	}
	
	@RequestMapping(value="event_list")
	public ModelAndView event_list(Model model) {
		ModelAndView mv = new ModelAndView();
		ArrayList<HashMap<String,Object>> eventList = new ArrayList<HashMap<String,Object>>();		
		eventList = eventService.getEventList();
	
		int cnt = 0;
		for(HashMap<String,Object> item : eventList) {
			System.out.println("cnt = " + ++cnt + " - EVENTID = " + item.get("EVENTID"));
			String filename = item.get("EVENTID").toString();
			filename = CommonUtil.encodeURL(filename, "utf-8");
			item.put("EVENTID_ENC", filename);
		}
		System.out.println("event = " + eventList.get(0));
		mv.addObject("eventList", eventList);		
		mv.setViewName("event_list");
		mv.addObject("LOC", "EVENT");
		return mv;
	}
	
	@RequestMapping(value="event_view")
	public ModelAndView event_view(Model model) {
		ModelAndView mv = new ModelAndView();
		
		mv.setViewName("event_view");
		return mv;
	}
}
